*****************************************************************************
*SET UP
*****************************************************************************
global root_dir = ""
di "$root_dir"

do "${root_dir}/Code/setup.do"

**************************************************************************************
***** FIGURE VII - CHAT DURATION DURING AI SYSTEM OUTAGES
**************************************************************************************
use "$workdir/outage_extract", clear

set seed 1234
egen recept_bin=xtile(receptivity_atai1), nq(5)
egen recept_bin3=xtile(receptivity_atai1), nq(3)

********************************************************************************************************************************************
* FIGURE VII PANEL A - Chat Duration during non-Outage Periods
********************************************************************************************************************************************
 eventdd aht if (ever_treated==0 | (ever_treated==1 & pre_treat==1 ) | (ever_treated==1 & post_treat==1 & flag_good_outage_period==0)) , ///
 timevar(weeks_since_treat) noend baseline(-1) leads(30) lags(20) accum method(hdfe, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id))  /// 
 graph_op($graphbackground ytitle($ytitle, size($ytitlesize)) xtitle($xtitle, size($xtitlesize)) ///
 xscale(r(-30 20)) xlabel(, labsize($xlabelsize) nogrid) xtick(-30(5)20) yscale(r(-20 20)) ytick(-20(5)20)  ylabel(-20(10)20, labsize($ylabelsize) nogrid) legend(off)  ///
 yline(0, lcolor(black) lwidth(medthick)) scheme(s2mono)) coef_op(mcolor(black)) ci(rcap, color(gs8))
graph export "${figures_dir}/figureVII_panelA.eps", as(eps) preview(on) replace  fontface($graphfont)

********************************************************************************************************************************************
* FIGURE VII PANEL B - Chat Duration during AI System Outages 
********************************************************************************************************************************************
eventdd aht if (ever_treated==0 | (ever_treated==1 & pre_treat==1 ) | (ever_treated==1 & post_treat==1 & flag_good_outage_period==1)) , ///
 timevar(weeks_since_treat) noend baseline(-1) leads(30) lags(20) accum method(hdfe, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id))  /// 
 graph_op($graphbackground ytitle($ytitle, size($ytitlesize)) xtitle($xtitle, size($xtitlesize)) ///
 xscale(r(-30 20)) xlabel(, labsize($xlabelsize) nogrid) xtick(-30(5)20) yscale(r(-20 20)) ytick(-20(5)20)  ylabel(-20(10)20, labsize($ylabelsize) nogrid) legend(off)  ///
 yline(0, lcolor(black) lwidth(medthick)) scheme(s2mono)) coef_op(mcolor(black)) ci(rcap, color(gs8))
 
graph export "${figures_dir}/figureVII_panelB.eps", as(eps) preview(on) replace  fontface($graphfont)

********************************************************************************************************************************************
* FIGURE VII PANEL C - Outage High Initial Adherence
********************************************************************************************************************************************
eventdd aht if (ever_treated==0 | (ever_treated==1 & pre_treat==1 & recept_bin3==3) | (ever_treated==1 & post_treat==1 & flag_good_outage_period==1 & recept_bin3==3 )) , ///
 timevar(weeks_since_treat) noend baseline(-1) leads(30) lags(20) accum method(hdfe, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id))  /// 
 graph_op($graphbackground ytitle($ytitle, size($ytitlesize)) xtitle($xtitle, size($xtitlesize)) ///
 xscale(r(-30 20)) xlabel(, labsize($xlabelsize) nogrid) xtick(-30(5)20) yscale(r(-20 20)) ytick(-20(5)20)  ylabel(-20(10)20, labsize($ylabelsize) nogrid) legend(off)  ///
 yline(0, lcolor(black) lwidth(medthick)) scheme(s2mono)) coef_op(mcolor(black)) ci(rcap, color(gs8))
 
graph export "${figures_dir}/figureVII_panelC.eps", as(eps) preview(on) replace  fontface($graphfont)

********************************************************************************************************************************************
* FIGURE VII PANEL D - *EVENT STUDY WITH OUTAGE POST PERIODS -- LOW RECEPT
********************************************************************************************************************************************
eventdd aht if (ever_treated==0 | (ever_treated==1 & pre_treat==1 & recept_bin3==1) | (ever_treated==1 & post_treat==1 & flag_good_outage_period==1 & recept_bin3==1)) , ///
  timevar(weeks_since_treat) noend baseline(-1) leads(30) lags(20) accum method(hdfe, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id))  /// 
 graph_op($graphbackground ytitle($ytitle, size($ytitlesize)) xtitle($xtitle, size($xtitlesize)) ///
 xscale(r(-30 20)) xlabel(, labsize($xlabelsize) nogrid) xtick(-30(5)20) yscale(r(-20 20)) ytick(-20(5)20)  ylabel(-20(10)20, labsize($ylabelsize) nogrid) legend(off)  ///
 yline(0, lcolor(black) lwidth(medthick)) scheme(s2mono)) coef_op(mcolor(black)) ci(rcap, color(gs8))
 
graph export "${figures_dir}/figureVII_panelD.eps", as(eps) preview(on) replace  fontface($graphfont)
